//
//  UIBarButtomItem+category.swift
//
//  Created by Visitor on 2017/2/27.
//  Copyright © 2017年 万利. All rights reserved.
//

import UIKit
extension UIBarButtonItem{

    class func BarButtomItemWithImage(imageName:String ,bgImageName:String  ,target: AnyObject?, action: Selector) ->UIBarButtonItem{
        let btn = UIButton()
        btn.setImage(UIImage(named:imageName), for: UIControlState())
        btn.setBackgroundImage(UIImage(named:bgImageName), for: UIControlState())
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        btn.frame = CGRect(x: 0, y: 0, width: 21, height: 21)
        return UIBarButtonItem(customView: btn)
    }
    
    convenience init(imageName:String ,bgImageName:String, title: String, titleClolr: UIColor, titleFont: CGFloat ,target: AnyObject?, action: Selector) {
//        self.init()
    let btn = UIButton()
    btn.setImage(UIImage(named:imageName), for: UIControlState())
    btn.setBackgroundImage(UIImage(named:bgImageName), for: UIControlState())
    btn.setTitle(title, for: .normal)
    btn.setTitleColor(titleClolr, for: .normal)
    btn.titleLabel?.font = FONT(font: titleFont)
    btn.sizeToFit()
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0)
        btn.frame.size.width += 5
    btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
//    self.customView = btn
    self.init(customView: btn)
    }
    
    convenience init(title: String, titleClolr: UIColor, titleFont: CGFloat) {
    let btn = UIButton()
    btn.setTitle(title, for: .normal)
    btn.setTitleColor(titleClolr, for: .normal)
    btn.titleLabel?.font = FONT(font: titleFont)
    btn.frame = CGRect(x: 0, y: 0, width: 90, height: 35)
    self.init(customView: btn)
    }
}


